const router = require('koa-router')()
var act = require('../controller/common.js');
router.prefix('/users')
//获取用户信息 ok
router.get('/u/:id', async (ctx, next) =>{
  let _id = ctx.params.id;
  let data = await act.getUserById(_id);  
  ctx.body = data;
})
//用户注册 ok
router.post('/register', async (ctx, next) =>{
  let name = ctx.params.name;
  let res = await act.getUser(name);
  console.log("res:"+res);
  ctx.body = res;
})
//TODO:检查用户
router.post('/login', async (ctx, next) =>{
  let name = ctx.params.name;
  let res = await act.getUser(name);
  console.log("res:"+res);
  ctx.body = res;
})
//TODO:更新用户
router.post('/update', async (ctx, next) =>{
  let name = ctx.params.name;
  let res = await act.getUser(name);
  console.log("res:"+res);
  ctx.body = res;
})
//获取用户 ok
router.get('/getUser', async (ctx, next) =>{
  let res = await act.allUser();
  ctx.body = res;
  next();
})

module.exports = router
